import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

//make sure there's another user (has next)
//Get user id (nextid)
//get users name (idToName)
//after someone wins (idWin)

public class getUserFromSite {

	String userName = "", userID = "", inputLine = "";

	public void userWon(String winner) throws IOException {
		URL user = new URL(
				"http://cals.arizona.edu/rtip/qr/smallGame/idWin.php?hash=1234567890&id=" + winner);
		URLConnection uW = user.openConnection();
		uW.getInputStream();
	}

	public String getUserID() throws Exception {
		URL user = new URL(
				"http://cals.arizona.edu/rtip/qr/smallGame/hasNext.php");
		URLConnection yc = user.openConnection();
		BufferedReader in = new BufferedReader(new InputStreamReader(
				yc.getInputStream()));

		while ((inputLine = in.readLine()) != null)
			if (inputLine.equals("true")) {
				user = new URL(
						"http://cals.arizona.edu/rtip/qr/smallGame/nextId.php?hash=1234567890");
				URLConnection yc1 = user.openConnection();
				BufferedReader in1 = new BufferedReader(new InputStreamReader(
						yc1.getInputStream()));
				while ((userID = in1.readLine()) != null)
					return userID;
				in1.close();
			}
		
			else
				userID = "";
		
		return userID;
	}

	public String getUserName() throws Exception {
		URL user = new URL(
				"http://cals.arizona.edu/rtip/qr/smallGame/idToName.php?id="
						+ userID);
		URLConnection yc11 = user.openConnection();
		BufferedReader in11 = new BufferedReader(new InputStreamReader(
				yc11.getInputStream()));
		while ((userName = in11.readLine()) != null)
			return userName;

		in11.close();

		return userName;
	}
}